<?php

class UniqueResultAction extends ShellAction {

	private $destFile;
	private $sourceFile;
    public function __construct($actionName, $cmd) {
   		parent::__construct($actionName, $cmd);       
    }

    public function execute(ezcWorkflowExecution $execution) {
    	$source	= CJSON::decode($execution->getVariable('source'));
		$dest	= CJSON::decode($execution->getVariable('dest'));
		
    	$runtime	= getenv('RUNTIME');
    	$tableName	= $dest['storage'];
    	$uniqueKey	= $source['filter']['unique'];
    	
    	$this->sourceFile = $execution->getVariable('sourceFile');
    	$this->destFile = "{$runtime}/output/{$tableName}";
    	
    	$this->cmd = $this->concreteParams($this->cmd, array(
    		':sourceFile'	=>	$this->sourceFile,
    		':destFile'		=>	$this->destFile,
    		':uniqueKey'	=>	$uniqueKey,
    		)
    	);
 		return parent::execute($execution);
    }
    
	public function getResultSize() {
        return filesize($this->destFile);
    }

    public function getResultCount() {
        return count(file($this->destFile));
    }
}